<?php	

session_start();
function sendErrorPage($mesg) 
{
    printf("<br><center>%s</center>", $mesg);
}

/* Checking the session authentication */
	//

function isSessionAuthenticated() 
{
    global $isAuthenticated;
    global $sessionType;
    global $username;

    //if (session_is_registered("isAuthenticated") && $isAuthenticated) {

		return true;

	//} else {
	//return false;
    //}
}

function showColorOption($item, $result) {
	mysql_data_seek ($result, 0);
	while($colors=mysql_fetch_array($result)){
		if($item == $colors["code"]) $set="selected";
		else $set="";
		echo "<option value=" . $colors["code"] . " $set>" . $colors["color"];
	}
}

function showParentOption($site_id,$link_parent){
	$sql="SELECT * FROM site_navbar WHERE site_id='$site_id' AND link_parent=0 ORDER BY link_text";

	$result = mysql_query($sql);
	echo "<option value=0>NONE</option>";
	while($data=mysql_fetch_array($result)){
		if($link_parent == $data["id"]) $set="selected";
		else $set="";
		echo "<option value=" . $data["id"] . " $set>" . stripslashes($data["link_text"])."</option>";
	}

}


function pk_color($cont_name, $obj_cnt)
{
if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE"))
echo "<script language=JavaScript src='inc/color_picker.js'></script>";
else
echo "<script language=JavaScript src='inc/inc/color_picker.js'></script>";
echo"
<script>
document.onclick=hideAll;
function hideAll()
{
oColor1.hide();
oColor2.hide();
oColor3.hide();
oColor4.hide();
oColor5.hide();
oColor6.hide();
oColor7.hide();
oColor8.hide();
oColor9.hide();
oColor10.hide();
}
</script>
<script>
var oColor".$obj_cnt." = new IColorPicker(\"oColor".$obj_cnt."\");
oColor".$obj_cnt.".onPickColor = new Function(\"document.getElementById('$cont_name').value=oColor".$obj_cnt.".color\");
oColor".$obj_cnt.".RENDER();
</script>
<INPUT type=\"button\" value=\"Color\" onClick=\"oColor".$obj_cnt.".show(this); event.cancelBubble=true;\">";
}

function auto_pilot_activation($uid)
{
$sql="SELECT * FROM site_home WHERE id='101'";
		$result = mysql_query($sql);
		$num=1;
		if($main_data=mysql_fetch_array($result)){
			$sql="INSERT INTO `site_home` (`logo` , `logo_alt` , `company_name` , `company_name_img` , `company_name_img_alt` , `slogan` , `contact_info` , `copyright` , `page_bg_image` , `page_bg_color` , `page_text_color` , `page_link_text_color` , `page_link_visited_color` , `page_link_rollover_color` , `menu_link_text_color` , `menu_link_visited_color` , `menu_link_rollover_color` , `meta_keywords` , `meta_description` , `meta_title` , `paypal_id` , `payment_ins` , `product_profit_pct` , `product_tax_pct` , `product_shipping_amt` , `sync_logo` , `sync_navbar` , `sync_contact_info` , `sync_skin` , `sync_paypal` , `sync_pricing` , `sync_meta` , `sync_all`, page_title_color ) VALUES ('" . mysql_escape_string ($main_data["logo"]) . "', '" . mysql_escape_string($main_data["logo_alt"]) . "', '" .mysql_escape_string($main_data["company_name"]) . "', '" . mysql_escape_string($main_data["company_name_img"]) . "', '" . mysql_escape_string($main_data["company_name_img_alt"]) . "', '" . mysql_escape_string($main_data["slogan"]) . "', '" . mysql_escape_string($main_data["contact_info"]) . "', '" . mysql_escape_string($main_data["copyright"]) . "', '" . mysql_escape_string($main_data["page_bg_image"]) . "', '" . $main_data["page_bg_color"] . "', '" . $main_data["page_text_color"] . "', '" . $main_data["page_link_text_color"] . "', '" . $main_data["page_link_visited_color"] . "', '" . $main_data["page_link_rollover_color"] . "', '" . $main_data["menu_link_text_color"] . "', '" . $main_data["menu_link_visited_color"] . "', '" . $main_data["menu_link_rollover_color"] . "', '" . mysql_escape_string($main_data["meta_keywords"]) . "', '" . mysql_escape_string($main_data["meta_description"]) . "', '" . mysql_escape_string($main_data["meta_title"]) . "', '" . $main_data["paypal_id"] . "', '" . mysql_escape_string($main_data["payment_ins"]) . "', '" . $main_data["product_profit_pct"] . "', '" . $main_data["product_tax_pct"] . "', '" . $main_data["product_shipping_amt"] . "', '" . $main_data["sync_logo"] . "', '" . $main_data["sync_navbar"] . "', '" . mysql_escape_string($main_data["sync_contact_info"]) . "', '" . $main_data["sync_skin"] . "', '" . $main_data["sync_paypal"] . "', '" . $main_data["sync_pricing"] . "', '" . $main_data["sync_meta"] . "', '" . $main_data["sync_all"] . "', '" . $main_data["page_text_color"] . "')";
			//echo '***INSERT QRY: '.$sql;
			/*$Inres=*/mysql_query($sql);
			//echo "Result Id: ".$Inres;//exit;					
			$new_site_id=mysql_insert_id();
//echo "<BR>*******New site Id : ".$new_site_id."******<BR>";
			$c_n_i=$main_data["company_name_img"];
			if("$c_n_i" != "") copy("./photos/${site_id}_" .$c_n_i,"./photos/${new_site_id}_" . $c_n_i);// 

			$logo=$main_data["logo"];
			if("$logo" != "") copy("./logos/${site_id}_" ."frontlogo.jpg" ,"./logos/${new_site_id}_" . $logo);//$logo

			$b_bg_i=$main_data["page_bg_image"];
			if("$b_bg_i" !="") copy("./photos/header/${site_id}_" . $b_bg_i,"./photos/header/${new_site_id}_" . $b_bg_i);
		}
		
		$date=date("Y-m-d");
		if("$subs_type"=="M") $end_dt = strftime("%Y-%m-%d", strtotime($join_dt) + mktime(0, 0, 0, 2, 1, 1970));
		if("$subs_type"=="Q") $end_dt = strftime("%Y-%m-%d", strtotime($join_dt) + mktime(0, 0, 0, 4, 4, 1970));
		if("$subs_type"=="S") $end_dt = strftime("%Y-%m-%d", strtotime($join_dt) + mktime(0, 0, 0, 7, 5, 1970));
		if("$subs_type"=="A") $end_dt = strftime("%Y-%m-%d", strtotime($join_dt) + mktime(0, 0, 0, 1, 1, 1971));

		$sql="UPDATE reseller SET active='Y', subs_type='$subs_type', join_dt='$join_dt', end_dt='$end_dt', site_id=$new_site_id WHERE uid='$uid'";
		//echo $sql;
		mysql_query($sql);

		$sql="INSERT INTO subs_detail (uid, start_dt, end_dt, renewal_dt) values('$uid', '$join_dt', '$end_dt', '$date')";
		//echo $sql;
		mysql_query($sql);

		$new_nav_res = mysql_query("SELECT MAX(id) FROM site_navbar");
		$new_nav_row = mysql_fetch_row($new_nav_res);
		$new_navbar_base=$new_nav_row[0] + 1;


$rsql="Select * from site_page where site_id=101";
$rres=mysql_query($rsql);
		while($rrow=mysql_fetch_array($rres))
		{
			$Iqry="INSERT INTO site_page (site_id, page_title, page_content, page_content_img, page_content_img_alt, page_content_ic, banner, banner_link, meta_keywords, meta_description, meta_title, admin_pg) VALUES ('$new_site_id','" . mysql_escape_string($rrow["page_title"]) . "','" . mysql_escape_string($rrow["page_content"]) ."', '" . $rrow["page_content_img"] . "', '" . $rrow["page_content_img_alt"] . "', 'C', '" . $rrow["banner"] . "', '" . $rrow["banner_link"] . "', '" . $rrow["meta_keywords"] ."', '" . $rrow["meta_description"] . "', '" . $rrow["meta_title"] . "', 'Y')";
			//echo $Iqry;
			mysql_query($Iqry);
		}
		//Pages Inserted.

$nsql="select * from site_navbar where site_id=101 ORDER BY link_position, link_text ";
$nres=mysql_query($nsql);
while($nrow=mysql_fetch_array($nres))
	{
		$page_title=mysql_escape_string($nrow["link_page_title"]);
		$link_text=mysql_escape_string($nrow["link_text"]);
		$link_page_title=mysql_escape_string($nrow["link_page_title"]);
		$link_parent=$nrow["link_parent"];
		$link_position=$nrow["link_position"];
		$new_navbar_id=$new_navbar_base;		
		$new_link_parent=0;
		//GET Link Parent Id.	
			
		if($link_parent!=0)
		{
		$pqry="select * from site_navbar where id=$link_parent";
		$pres=mysql_query($pqry);
		
		if($prow=mysql_fetch_array($pres))
		$parent_title=mysql_escape_string($prow["link_page_title"]);
		
		if($parent_title!="")
		{
		$piqry="select * from site_navbar where site_id='$new_site_id' and link_page_title='$parent_title'";
		//echo $piqry;
		$pires=mysql_query($piqry);
		if($pirow=mysql_fetch_array($pires))		
		$new_link_parent=mysql_escape_string($pirow["id"]);		
		}
		}
		//GET Link Page Id.
		$nqry="select * from site_page where site_id='$new_site_id' and page_title='$page_title'";		
//		echo $nqry;
		$nvres=mysql_query($nqry);
		if($nvrow=mysql_fetch_array($nvres))
		$new_link_page=$nvrow["id"];
		//echo "<BR>".$new_link_page;
		$Inqry="INSERT INTO site_navbar VALUES($new_navbar_id, $new_site_id, '$link_text', $new_link_page, '$page_title', $new_link_parent, '$link_position','Y', 'Y')";
		//echo $Inqry;
		mysql_query($Inqry);
		$new_navbar_base++;
	}//Links Inserted	

}
?>